#ifndef __DS18B20_H
#define __DS18B20_H

#include "../../imx6ul/imx6ul.h"
#include "../delay/bsp_delay.h"

#define DQ_OUT_MODE() (GPIO5->GDIR |= (0x1 << 2))
#define DQ_IN_MODE() (GPIO5->GDIR &= ~(0x1 << 2))
#define HIGH 1
#define LOW 0
// 电平状态
#define DQ_INPUT_LEVEL() ((GPIO5->PSR & (0x1 << 2)) ? HIGH : LOW)
#define DQ_OUTPUT_LEVEL(level)                                                 \
  do {                                                                         \
    GPIO5->DR &= ~(0x1 << 2);                                                  \
    GPIO5->DR |= (level << 2);                                                 \
  } while (0)

#define DQ_DELAY_US(x) delay_us(x)

uint8_t DS18B20_Detect(void);
void DS18B20_Init(void);
uint8_t DS18B20_Read_Bit();
void DS18B20_Write_Bit(uint8_t bit);
uint8_t DS18B20_Read_Byte(void);
void DS18B20_Write_Byte(uint8_t byte);
void DS18B20_Read_Id(uint8_t *id);
float DS18B20_Read_Temperature(void);

#endif
